package com.neo.office.server.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neo.office.server.config.data.Result;
import com.neo.office.server.domain.entity.MenuRole;
import com.neo.office.server.mapper.MenuRoleMapper;
import com.neo.office.server.service.MenuRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements MenuRoleService {

    @Autowired
    private MenuRoleMapper menuRoleMapper;

    @Override
    @Transactional
    public Result updateMenuRole(Integer rid, Integer[] mids) {
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        if (mids == null || mids.length == 0){
            return Result.success("更新成功");
        }
        Integer result = menuRoleMapper.insertRecord(rid,mids);
        if (result == mids.length){
            return Result.success("更新成功");
        }
        return Result.error("更新失败");
    }

}
